#The Hunger Games
#Developed by Shreyan J. and Rasvik K.

from random import randint
from random import shuffle

def repCreate(hunts, slacks):
    players = len(slacks)
    reps = []
    for i in range(players):
        reps += [round(float(hunts[i])/float(hunts[i]+slacks[i]),2)]
    return reps

def endGame(rnd):
    v = randint(100,350)
    return v<rnd
    

def roundDisplay(rnd): print "Round", rnd

def repDisplay(names, reps):
    players = len(names)
    print "Your reputation is", reps[0]
    otherReps = reps[1:]
    shuffle(otherReps)
    print "The other tributes reputations are",
    for c in otherReps: print c,
    m = randint(1, players*(players-1)-1)#The randint function is inclusive
    print "\nYour tribe's hunting goal is",m
    return m
#this hunting goal is "m"

def foodDisplay(food):  print "You have", food[0], "food points"


print "Hello.  I am your tribe's leader."
playerName = raw_input("What is your name?  ")
print "Well, "+ playerName + ", I wish you luck in survival."
TribeMembers = raw_input("How many people are in our tribe again, including yourself?  ")
if len(TribeMembers)==1:
    if TribeMembers in "012":
        print "No, thats too few.  There are 3."
        TribeMembers=3
    elif TribeMembers in "3456789":
        print "Correct!"
        TribeMembers = int(TribeMembers)
else:
    TribeMembers=10
    if TribeMembers == "10":
        print "Correct!"
        
    else: print "Nope.  That's too many. There are only 10."
print ""

tributeNames = ["you", "Joe", "Cady", "Shawn", "Bryan", "Guan", "Hannah", "Lizy", "Katy", "Taylor"][:TribeMembers]
tributeHunts = TribeMembers*[0]
tributeSlacks = TribeMembers*[0]
tributeReps = TribeMembers*[0]
tributeFood = TribeMembers*[300*(TribeMembers-1)]
roundNumber = 1
dead = 0

while 1:
    roundDisplay(roundNumber)
    m=repDisplay(tributeNames, tributeReps)
    foodDisplay(tributeFood)
    raw_input("Press <ENTER> to continue")
    print "\n"
    totalHunts = 0
    index=1
    otherTributes = tributeNames[1:]
    playersLeft = len(tributeFood)
    
    for index, partner in enumerate(otherTributes):
        print "Hunt or Slack with,",partner+'?'
        playerHS = raw_input("Type H for Hunt and S for Slack: ")
        if playerHS == 'H': playerHS=1
        else: playerHS=0
        
        partnerHS = randint(0,1)


        
        if partnerHS==0:
            print partner, "will slack\n"
            tributeSlacks[index+1] = tributeSlacks[index+1] + 1
            
            if playerHS==0:
                tributeSlacks[0] = tributeSlacks[0]+1
                tributeFood[0] = tributeFood[0]-2
                tributeFood[index+1] = tributeFood[index+1]-2
                
                
            if playerHS==1:
                tributeHunts[0] = tributeHunts[0] + 1
                tributeFood[0] = tributeFood[0] -3
                tributeFood[index+1] = tributeFood[index+1] + 1
                totalHunts+=1
            
                
        else:
            print partner, "will hunt\n"
            tributeHunts[index+1] = tributeHunts[index+1] + 1
        
            if playerHS==0:
                tributeSlacks[0] = tributeSlacks[0]+1
                tributeFood[0] = tributeFood[0] +1
                tributeFood[index+1] = tributeFood[index+1]-3
                totalHunts+=1
                

            if playerHS==1:
                tributeHunts[0] = tributeHunts[0]+1
                totalHunts+=2
                

    

                  
    

    for xindex, tributeX in enumerate(otherTributes):
        for yindex, tributeY in enumerate(otherTributes[xindex+1:]):

            xHS = randint(0, 1)
            yHS = randint(0,1)
            
            yindex += 1+xindex
            if xHS==0:
                tributeSlacks[xindex+1] = tributeSlacks[xindex+1] + 1
                
                if yHS==0:
                    tributeSlacks[yindex+1] = tributeSlacks[yindex]+1
                    tributeFood[xindex+1] = tributeFood[xindex+1]-2
                    tributeFood[yindex+1] = tributeFood[yindex+1]-2
                    
                    
                elif yHS==1:
                    tributeHunts[yindex+1] = tributeHunts[yindex+1] + 1
                    tributeFood[xindex+1] = tributeFood[xindex+1] + 1
                    tributeFood[yindex+1] = tributeFood[yindex+1] - 3
                    totalHunts+=1
                    
                
            else:
                tributeHunts[xindex+1] = tributeHunts[xindex+1] + 1
            
                if yHS==0:
                    tributeSlacks[yindex+1] = tributeSlacks[yindex+1] + 1
                    tributeFood[xindex+1] = tributeFood[xindex+1] - 3
                    tributeFood[yindex+1] = tributeFood[yindex+1] + 1
                    totalHunts+=1
                    

                elif yHS==1:
                    tributeHunts[yindex+1] = tributeHunts[yindex+1]+1
                    totalHunts+=2
                    
        
    if totalHunts > m:
        for i in range(playersLeft):
            tributeFood[i] = tributeFood[i] + 2*(playersLeft -1 )
        print "Your tribe has reached its hunting goal,", 2*(playersLeft-1), "food points for everybody!"
    else: print "Your tribe has failed to reach its hunting goal, so no bonus food for the tribe."
    
    print "Your tribe has hunted", totalHunts,"times this round."
    newNames = list(tributeNames)
    for tribute in newNames:
        i = tributeNames.index(tribute)
        
        if tributeFood[i] <= 0:
            if i==0:
                print "You died.  You ran out of food. You survived", roundNumber-1, "rounds."
                dead=1
                break
    

        
            print tributeNames[i], "has ran out of food and died."
            del tributeFood[i]
            del tributeNames[i]
            del tributeReps[i]
            del tributeSlacks[i]
            del tributeHunts[i]
            
    
    if dead==1: break

    tributeReps = repCreate(tributeHunts, tributeSlacks)
    if len(tributeNames)==1:
        print "You are the lone survivor of your tribe. You win the Survivors Prize, freedom from the hunger games!"
        break
    elif len(tributeNames)==0:
        print "Everyone has died of famine."
        break
    if endGame(roundNumber):
        print "Everyone in your tribe, including yourself, has died due to an unknown reason."
        break
    print "\n"
              
    
    roundNumber = roundNumber + 1
    
                   


